//
//  UIImageView+Circle.m
//  Common
//
//  Created by slj on 2017/8/15.
//  Copyright © 2017年 cloudstone. All rights reserved.
//

#import "UIView+Circle.h"
#import <AVFoundation/AVFoundation.h>

@implementation UIView(Circle)

- (void)rn_drawCircle
{
    [self rn_drawCircle:CGRectZero];
}

- (void)rn_drawCircle:(CGRect)bounds
{
    [self rn_drawCircle:bounds cornerRadii:CGSizeZero];
}

- (void)rn_drawCircle:(CGRect)bounds cornerRadii:(CGSize)cornerRadii;
{
    if (CGRectEqualToRect(bounds,CGRectZero)) {
        bounds = self.bounds;
        cornerRadii = self.bounds.size;
    }
    else if (CGSizeEqualToSize(cornerRadii,CGSizeZero)) {
        cornerRadii = bounds.size;
    }
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds
                                                   byRoundingCorners:UIRectCornerAllCorners
                                                         cornerRadii:cornerRadii];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    //设置大小
    maskLayer.frame = bounds;
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}

@end
